//
//  WXPAuthIDCardInputView.m
//  MexicoLoan
//
//  Created by wxp on 2025/2/28.
//

#import "WXPAuthIDCardInputView.h"

@implementation WXPAuthIDCardInputView

#pragma mark - lazy
- (UIView *)viewBack{
    if (_viewBack == nil) {
        _viewBack = [UIView new];
        _viewBack.backgroundColor = COLOR_WHITE;
    }
    return _viewBack;
}
- (UILabel *)labelTitle{
    if (_labelTitle == nil) {
        _labelTitle = [UILabel new];
        _labelTitle.textColor = COLOR_BLACK;
        _labelTitle.fontNum = 12;
    }
    return _labelTitle;
}
- (UIView *)viewContentBack{
    if (_viewContentBack == nil) {
        _viewContentBack = [UIView new];
        _viewContentBack.userInteractionEnabled = true;
        _viewContentBack.backgroundColor = [UIColor colorWithHexString:@"#F6F6F6"];
        [GlobalMethod setRoundView:_viewContentBack color:[UIColor clearColor] numRound:16 width:0];
    }
    return _viewContentBack;
}
- (UILabel *)labelNameTitle{
    if (_labelNameTitle == nil) {
        _labelNameTitle = [UILabel new];
        _labelNameTitle.textColor = COLOR_LIGHT_GRAY;
        _labelNameTitle.fontNum = 12;
    }
    return _labelNameTitle;
}
- (UITextField *)tfName{
    if (_tfName == nil) {
        _tfName = [UITextField new];
        _tfName.font = [UIFont boldSystemFontOfSize:12];
        _tfName.textColor = COLOR_BLACK;
        _tfName.borderStyle = UITextBorderStyleNone;
        _tfName.backgroundColor = [UIColor clearColor];
        _tfName.placeholder = @"Confirmar su nombre y apellido";
    }
    return _tfName;
}
- (UILabel *)labelNumberTitle{
    if (_labelNumberTitle == nil) {
        _labelNumberTitle = [UILabel new];
        _labelNumberTitle.textColor = COLOR_LIGHT_GRAY;
        _labelNumberTitle.fontNum = 12;
    }
    return _labelNumberTitle;
}
- (UITextField *)tfNumber{
    if (_tfNumber == nil) {
        _tfNumber = [UITextField new];
        _tfNumber.font = [UIFont boldSystemFontOfSize:12];
        _tfNumber.textColor = COLOR_BLACK;
        _tfNumber.borderStyle = UITextBorderStyleNone;
        _tfNumber.backgroundColor = [UIColor clearColor];
        _tfNumber.placeholder = @"Confirmar su número de identificación";
    }
    return _tfNumber;
}


#pragma mark - 初始化
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.widthHeight = XY(SCREEN_WIDTH, 0);
        self.backgroundColor = [UIColor clearColor];
        [self addSubView];
    }
    return self;
}

- (void)addSubView{
    [self addSubview:self.viewBack];
    [self.viewBack addSubview:self.labelTitle];
    [self.viewBack addSubview:self.viewContentBack];
    [self.viewContentBack addSubview:self.labelNameTitle];
    [self.viewContentBack addSubview:self.tfName];
    [self.viewContentBack addSubview:self.labelNumberTitle];
    [self.viewContentBack addSubview:self.tfNumber];
    [self resetView];
}

#pragma mark - 刷新View
- (void)resetView{
    self.viewBack.width = SCREEN_WIDTH - 2*LEFT_MARDIN;
    [self.labelTitle fitTitle:@"Confirmar las informaciones siguientes" variable:0];
    self.labelTitle.leftTop = XY(LEFT_MARDIN, Ratio(20));
    
    self.viewContentBack.width = self.viewBack.width-2*LEFT_MARDIN;
    
    [self.labelNameTitle fitTitle:@"Nombre:" variable:0];
    self.labelNameTitle.left = LEFT_MARDIN;
    [self.labelNumberTitle fitTitle:@"Número:" variable:0];
    self.labelNumberTitle.left = self.labelNameTitle.left;
    
    self.tfName.widthHeight = XY(self.viewContentBack.width-LEFT_MARDIN-70, Ratio(18+15));
    self.tfName.leftTop = XY(75, Ratio(13));
    self.labelNameTitle.centerY = self.tfName.centerY;
    
    self.tfNumber.widthHeight = self.tfName.widthHeight;
    self.tfNumber.leftTop = XY(self.tfName.left, self.tfName.bottom+1);
    self.labelNumberTitle.centerY = self.tfNumber.centerY;
    
    self.viewContentBack.height = self.tfNumber.bottom+self.tfName.top;
    self.viewContentBack.centerXTop = XY(self.viewBack.width/2, self.labelTitle.bottom+Ratio(18));
    
    self.viewBack.height = (self.viewContentBack.bottom+1);
    
    UIBezierPath * maskPath = [UIBezierPath bezierPathWithRoundedRect:self.viewBack.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(16, 16)];
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.frame = self.viewBack.bounds;
    maskLayer.path = maskPath.CGPath;
    self.viewBack.layer.mask = maskLayer;
    
    self.viewBack.centerXTop = XY(self.width/2, 0);
    self.height = self.viewBack.bottom;
}

@end
